#include "Hobbit.h"
using namespace std;

const unsigned int Hobbit::ens = 3;

const unsigned int Hobbit::nbr_comp = 5;

const unsigned int Hobbit::ensemble_racial[3][5] =
  { {1 ,  9,  6,  3,  8}, // costauds
    {1 ,  4,  3, 11,  8}, // grand-gars
    {1 ,  3,  8,  0,  0}  // pieds-velus
  };

const unsigned int Hobbit::taille = 14;

const ListCapa Hobbit::Liste[14] = {
  {"Bonus à l'attaque"  ,  5},
  {"Bonus à la réaction",  5},
  {"Bonus aux JS"       ,  5},
  {"Camouflage"         , 10},
  {"Détection du mal"   ,  5},
  {"Détection minière"  ,  5},
  {"Dextérité renforcée", 20},
  {"Furtivité"          , 10},
  {"Infravision"        ,  5},
  {"Moquerie"           ,  5},
  {"Portes secrètes"    ,  5},
  {"Costaud"            , 35},
  {"Grand-Gars"         , 35},
  {"Pieds-Velus"        , 30},
};

Hobbit::Hobbit(vector<unsigned int> cap)
  :Race("Hobbit")
{
  for (unsigned int i(0); i < cap.size(); i++)
    capacites.push_back(cap[i]);
}

Hobbit::Hobbit(unsigned int& PP)
  :Race("Hobbit")
{
  dout(BLANK) << setfill('*') << setw(56) << '*' << endl;
  dout(BLANK) << "Création d'un hobbit" << endl << endl;
  
  unsigned int nbr(0);
  bool test(true), deja_pris, encore(false);
  PP = 35;
  do
    {
      dout(BLANK) << "Tu as 35 pp à dépenser" << endl;
      for (unsigned int i(0); i<taille; i++)
	dout(BLANK) << i+1 << ' ' << (Liste[i].Capa)
		    << " (" << Liste[i].Cout << " pp)" << endl;
      dout(BLANK) << taille+1 << " Aucune" << endl;
      dout(BLANK) << "Choisir les capacités raciales" << endl;
      while(test)
	{
	  nbr = demander_unsigned_borne("("+write_int(PP)+" pp restants ",
					1, taille + 1);
	  if (nbr == taille+1)
	    test = false;
	  else
	    {
	      if (PP >= Liste[nbr-1].Cout)
		{
		  PP -= Liste[nbr-1].Cout;
		  if (nbr<13)
		    {
		      deja_pris = safe_push_back(&capacites, nbr - 1);
		      if (deja_pris)
			dout(WARN) << "Déjà sélectionné" << endl;
		      else
			{
			  capacites.push_back(nbr-1);
			  dout(BLANK) << "Capacité choisie : "
				      << (Liste[nbr-1].Capa) << endl;
			}
		    }
		  else
		    {
		      dout(BLANK) << "Achat de l'ensemble racial : "
				  << (Liste[nbr-1].Capa) << endl;
		      for (unsigned int i(0); i < nbr_comp; i++)
			{
			  if (ensemble_racial[nbr-13][i] != 0)
			    capacites.push_back(ensemble_racial[nbr-13][i]-1);
			}
		    }
		}
	      else
		dout(BLANK) << "Pas assez de pp" << endl;
	    }
	}
      
      affiche_info();
      dout(BLANK) << endl <<  "1 pour continuer, 2 pour recommencer" << endl;
      nbr = demander_unsigned_borne("Choix ", 1, 2);
      if (nbr == 2)
	{
	  PP = 35;
	  capacites.clear();
	  test = true;
	  encore = true;
	  dout(BLANK) << endl;
	}
      else
	encore = false;
    }
  while(encore);
  
  dout(BLANK) << endl << setfill('*') << setw(56) << '*' << endl;
}

Hobbit::~Hobbit()
{}

void Hobbit::appliquer_ajustements(unsigned int tab[6])
{
  tab[1]++;
  tab[0]--;
}

void Hobbit::affiche_info()
{
  dout(BLANK) << "Race : " << Type << endl;
  for (unsigned int i(0); i<capacites.size(); i++)
    dout(BLANK) << (Liste[capacites[i]].Capa) << endl;
}

string Hobbit::get_capacite(const unsigned int& i) const
{
  return (Liste[get_capa(i)].Capa);
}
